/**
 * Copyright 2011 FeedDreamwork SIG
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.feeddreamwork.feed;

import java.io.*;

import org.w3c.dom.*;
import org.xml.sax.*;

public final class FeedParsers {
	private static Atom10FeedParser atom10Parser = new Atom10FeedParser();
	private static Rss20FeedParser rss20Parser = new Rss20FeedParser();

	public static Feed parse(Document source, String baseURL)
			throws FeedParsingException {
		if (atom10Parser.isThisType(source))
			return atom10Parser.parse(source, baseURL);
		if (rss20Parser.isThisType(source))
			return rss20Parser.parse(source, baseURL);
		throw new FeedParsingException();
	}

	public static Feed parse(String source, String baseURL)
			throws FeedParsingException {
		try {
			return parse(XMLUtils.parseDocument(source), baseURL);
		} catch (IOException e) {
			throw new FeedParsingException();
		} catch (SAXException e) {
			throw new FeedParsingException();
		}
	}

	private FeedParsers() {
	}
}
